﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace LitTools
{
    /// <summary>
    /// 物体对象池
    /// </summary>
    public class GameObjectPool : ObjectPool<GameObjectPoolItem>
    {
        /// <summary>
        /// item的预制体
        /// </summary>
        public GameObject itemPrefab;
        /// <summary>
        /// item的父物体
        /// </summary>
        public Transform itemParent;
        /// <summary>
        /// 在物体disable时回收
        /// </summary>
        public bool returnWhenDisable;
        /// <summary>
        /// 自动回收时间，不自动回收设置为0
        /// </summary>
        public float autoReturnTime;

        /// <summary>
        /// 创建实例
        /// </summary>
        /// <returns></returns>
        protected override GameObjectPoolItem CreateInstance()
        {
            if (itemPrefab == null)
            {
                Debug.LogError("itemPrefab can not be null");
                return null;
            }
            GameObjectPoolItem instance;
            if (itemParent != null)
                instance = GameObject.Instantiate(itemPrefab, itemParent).GetComponent<GameObjectPoolItem>();
            else
                instance = GameObject.Instantiate(itemPrefab).GetComponent<GameObjectPoolItem>();
            instance.pool = this;
            return instance;
        }
    }
}
